package edu.mercer.employmentcalculator;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;

public class CompareResult extends Activity
{
	// TODO: build common base Activity for this and CurrentCompensation
	
	private Bundle bundle;
	
	private TextView lblCurrentSalaryResult;
	private TextView lblPotentialSalaryResult;
	private TextView lblCurrentRaiseResult;
	private TextView lblPotentialRaiseResult;
	private ZipColiGetter _zipColiGetter;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.compare_result);
		
		this.bundle = getIntent().getExtras();
		this._zipColiGetter = new ZipColiGetter(this.getBaseContext(), true);
		
		this.lblCurrentSalaryResult = (TextView)findViewById(R.id.lblCurrentSalaryResult);
		this.lblPotentialSalaryResult = (TextView)findViewById(R.id.lblPotentialSalaryResult);
		this.lblCurrentRaiseResult = (TextView)findViewById(R.id.lblCurrentRaiseResult);
		this.lblPotentialRaiseResult = (TextView)findViewById(R.id.lblPotentialRaiseResult);
		
		DoCalculations();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

	private void DoCalculations()
	{
		Compensation current = new Compensation();
		current.setSalary(bundle.getDouble(Constants.CurrentSalary));
		current.setVacationDays(bundle.getInt(Constants.CurrentVacation));
		current.setHolidays(bundle.getInt(Constants.CurrentHolidays));
		current.setSickDays(bundle.getInt(Constants.CurrentSick));
		double currentColi = _zipColiGetter.GetColi(bundle.getInt(Constants.CurrentZip));
		current.setColi(currentColi);
		
		Compensation potential = new Compensation();
		potential.setSalary(bundle.getDouble(Constants.PotentialSalary));
		potential.setVacationDays(bundle.getInt(Constants.PotentialVacation));
		potential.setHolidays(bundle.getInt(Constants.PotentialHolidays));
		potential.setSickDays(bundle.getInt(Constants.PotentialSick));
		double potentialColi = _zipColiGetter.GetColi(bundle.getInt(Constants.PotentialZip));
		potential.setColi(potentialColi);
		
		DoCalculations(current, potential);
	}
	
	private void DoCalculations(Compensation current, Compensation potential)
	{
		double coliAdjustPotentialToCurrent = current.getColi() / potential.getColi();
		
		this.lblCurrentSalaryResult.setText("$" + String.format("%1$,.2f", current.CalculateEquivalentSalary()));
		double potentialSalaryInCurrentPower = potential.CalculateEquivalentSalary() * coliAdjustPotentialToCurrent;
		this.lblPotentialSalaryResult.setText("$" + String.format("%1$,.2f", potentialSalaryInCurrentPower));
		double equivCurrentRaise = potentialSalaryInCurrentPower - current.CalculateEquivalentSalary();
		this.lblCurrentRaiseResult.setText("$" + String.format("%1$,.2f", equivCurrentRaise));
		double equivPotentialRaise = equivCurrentRaise / (coliAdjustPotentialToCurrent);
		this.lblPotentialRaiseResult.setText("$" + String.format("%1$,.2f", equivPotentialRaise));
		
		// TODO: I don't think I've got the coli Adjustments just right....
	}
}
